import { request } from '@/plugins/request'

export const getArticles = (params) => {
    return request({
        method: 'get',
        url: '/api/articles',
        params
    })
}

export const getArticle = (slug) => {
    return request({
        method: 'get',
        url: `/api/articles/${slug}`,
    })
}

export const getYourFeedArticles = (params) => {
    return request({
        method: 'get',
        url: '/api/articles/feed',
        params,
    })
}

export const addFavorite = (slug) => {
    return request({
        method: 'post',
        url: `/api/articles/${slug}/favorite`,
    })
}

export const deleteFavorite = (slug) => {
    return request({
        method: 'delete',
        url: `/api/articles/${slug}/favorite`,
    })
}

export const getComments = (slug) => {
    return request({
        method: 'get',
        url: `/api/articles/${slug}/comments`,
    })
}

export const addComments = (slug, comment) => {
    return request({
        method: 'post',
        url: `/api/articles/${slug}/comments`,
        data: {
            comment: {
                body: comment
            }
        }
    })
}

export const addArticle = (article) => {
    return request({
        method: 'post',
        url: '/api/articles',
        data: {
            article
        }
    })
}

export const updateArticle = (article, slug) => {
    return request({
        method: 'put',
        url: `/api/articles/${slug}`,
        data: {
            article
        }
    })
}

export const deleteArticle = (slug) => {
    return request({
        method: 'delete',
        url: `/api/articles/${slug}`,
    })
}